# $Id: PKGBUILD 87081 2013-03-26 18:14:07Z alucryd $
# Maintainer: Maxime Gauduin <alucryd@gmail.com>
# Contributor: josephgbr <rafael.f.f1@gmail.com>
# Contributor: vEX <vex@niechift.com>

pkgname=pcsx2
pkgver=1.0.0
pkgrel=4
pkgdesc="A Sony PlayStation 2 emulator"
arch=('i686' 'x86_64')
url="http://www.pcsx2.net"
license=('GPL')
makedepends=('cmake' 'sparsehash')
if [[ $CARCH == "i686" ]]; then
  depends=('glew' 'libjpeg-turbo' 'portaudio' 'soundtouch' 'wxgtk')
elif [[ $CARCH == "x86_64" ]]; then
  makedepends+=('gcc-multilib' 'lib32-glew' 'lib32-libjpeg-turbo' 'lib32-mesa-libgl' 'lib32-portaudio' 'lib32-soundtouch' 'lib32-wxgtk')
  optdepends=('lib32-gtk-engines: gtk2 engines support'
              'lib32-gtk-aurora-engine: aurora gtk2 engine support'
              'lib32-gtk-murrine: murrine gtk3 engine support'
              'lib32-gtk-unico: unico gtk2 engine support')
fi
options=('!emptydirs')
source=("${pkgname}-${pkgver}-r5350-sources.7z::http://pcsx2.net/download/releases/source-code/finish/7-source/93-pcsx2-v1-0-0-source-code/0.html")
sha256sums=('3f6067c3ea23b2afa4d4c411f3121d86612c310b1c7a44413577cf5727e498bc')

build() {
  cd "${srcdir}"/${pkgname}-${pkgver}-r5350-sources

# Patch
  sed 's|0.9.8|1.0.0|' -i CMakeLists.txt

# Build
  if [[ -d build ]]; then
    rm -rf build
  fi
  mkdir build && cd build
  if [[ $CARCH == "i686" ]]; then
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DPACKAGE_MODE=TRUE -DXDG_STD=TRUE -DGLSL_API=TRUE -DREBUILD_SHADER=TRUE -DPLUGIN_DIR=/usr/lib/pcsx2 -DGAMEINDEX_DIR=/usr/share/pcsx2 -DGLSL_SHADER_DIR=/usr/share/pcsx2
  elif [[ $CARCH == "x86_64" ]]; then
    export CC="gcc -m32"
    export CXX="g++ -m32"
    export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DPACKAGE_MODE=TRUE -DXDG_STD=TRUE -DGLSL_API=TRUE -DREBUILD_SHADER=TRUE -DPLUGIN_DIR=/usr/lib32/pcsx2 -DGAMEINDEX_DIR=/usr/share/pcsx2 -DGLSL_SHADER_DIR=/usr/share/pcsx2 -DwxWidgets_CONFIG_EXECUTABLE=/usr/bin/wx-config32 -DwxWidgets_wxrc_EXECUTABLE=/usr/bin/wxrc32 -DCMAKE_LIBRARY_PATH=/usr/lib32
  fi
  make
}

package() {
  cd "${srcdir}"/${pkgname}-${pkgver}-r5350-sources/build

# Multilib
  if [[ $CARCH == "x86_64" ]]; then
    depends=('lib32-wxgtk' 'lib32-libgl' 'lib32-glew' 'lib32-libjpeg-turbo' 'lib32-portaudio' 'lib32-soundtouch')
  fi

# Install
  make DESTDIR="${pkgdir}" install
}

# vim: ts=2 sw=2 et:
